import { createApp } from 'vue'
import App from './App.vue'
import './style.css';
import { createPinia } from 'pinia'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import router from './router/index.js'
import 'virtual:windi.css'
import "./style/element_visiable.scss";
import locale from 'element-plus/dist/locale/zh-cn.mjs'
import { initTime } from '@/utils/init.js';
import { handleApiResponse } from './utils/request.js'

const app = createApp(App)
const pinia = createPinia()

for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

app.config.globalProperties.$handleApiResponse = handleApiResponse;
app.config.globalProperties.$initTime = initTime;

app.use(ElementPlus, {
    locale: locale,
    size: 'default'
}).use(pinia).use(router)


// 响应式文字大小
function adjustFontSize() {
    const width = window.innerWidth;
    const baseSize = 18; // 默认基准值
    const minSize = 14;  // 最小字体
    const maxSize = 22;  // 最大字体

    // 根据屏幕宽度动态计算字体大小
    let fontSize = baseSize;

    if (width < 600) {
        fontSize = minSize;
    } else if (width > 1200) {
        fontSize = maxSize;
    } else {
        // 线性插值计算
        fontSize = minSize + ((width - 600) / 600) * (maxSize - minSize);
    }

    // 设置根字体大小
    document.documentElement.style.fontSize = `${fontSize}px`;
}

// 初始化和窗口大小变化时调整
window.addEventListener('resize', adjustFontSize);
adjustFontSize(); // 首次加载时执行

app.mount('#app')